package com.异常.www;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-16
 * Time: 7:22
 */
public class Config {
    File file;
    //打开文件
    public  void openConfig(String filename) throws FileNotFoundException {
        // public void OpenConfig(String filename) throws IOException,FileNotFoundException{
        // FileNotFoundException 继承自 IOException
//        if(filename.endsWith(".ini")){
//            throw new IOException("文件不是.ini文件");
//        }
        if(filename.equals("config.ini")){
            throw new FileNotFoundException("配置文件名不对");
        }
    }

    public static void main(String[] args)  {
        try{
            Config config = new Config();
            config.openConfig("config.ini");
            System.out.println("文件打开成功");

        } catch (FileNotFoundException fileNotFoundException){
            //异常处理
            //System.out.println(fileNotFoundException.getMessage());
            fileNotFoundException.printStackTrace();
        }catch (Exception e){
            System.out.println("捕捉所有的异常");
        }
        System.out.println("其他代码逻辑，一旦异常被处理，这里的代码也会执行");
    }
}
